#include <cstdio>
#include <map>
#define int long long

using namespace std;

const int P=1e6;

int s[P],mod;

int fpow(int x,int p){
	int res=1;
	while(p){
		if(p&1) res=res*x%mod;
		x=x*x%mod;p>>=1;
	}
	return res;
}

int inv(int x){
	return fpow(x,mod-2);
}

struct pir{
	int x,y;
};

pir exgcd(int a,int b){
	if(!b) return (pir){1,0};
	pir k=exgcd(b,a%b);
	return (pir){k.y,k.x-a/b*k.y};
}

int ind_equ_p_x(int a,int p,int b){
	return (exgcd(a,p).x*b%p+p)%p;
}

signed main()
{
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	int n,m,D;scanf("%lld%lld%lld%lld",&n,&m,&D,&mod);
	++s[m%mod];for(int q=2;q<=D;++q){
		s[((fpow(q,m)-1)%mod+mod)%mod*inv(q-1)%mod]+=q;
	}
	int ans=1,smod=1e9+7;
	D=D*(D+1)/2%smod;
	for(int i=1;i<=n;++i){
		int a,b;scanf("%lld%lld",&a,&b);
		int x=ind_equ_p_x(a,mod,b);
		ans=(ans*((D-s[x])%smod+smod)%smod)%smod;
	}
	printf("%lld",ans);
}
